using System;
using System.Collections.Generic;
using System.Text;
using BoOnce.GameLogic.Entities;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using BoOnce.Components;
using BoOnce.Helpers;

namespace BoOnce.Steps
{
    class Egout : PhysicalScenery
    {
        private Texture2D _Texture;
        private Player _Player;

        public Egout(Vector2 position, Player player)
            : base (position, 40, 40, 1f)
        {
            _Player = player;
            _Texture = Game.Content.Load<Texture2D>(Settings.CONTENT_LEVEL_PATH + "/bus/egout");
            _Body.Enabled = true;
            _Geom.CollisionEnabled = false;
            _Body.IsStatic = true;
        }

        public override void QuickDraw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(_Texture, Camera.ToScreenPosition(Position), null, Color.White, _Body.TotalRotation, new Vector2(Width / 2.0f, Height / 2.0f), 1.0f, SpriteEffects.None, 0.0f); ;
        }

        int i = 0;
        public override void Update(GameTime gameTime)
        {
            if (this.Intersect(_Player) && IsActive(gameTime))
            {
                TimeOfLastIntersection = gameTime.TotalGameTime.TotalMilliseconds;
                Logger.WriteInfo("touche egout");
                i++;
            }
        }

        private double TimeOfLastIntersection = 0;
        private double MinDurationBetweenIntersection = 1500; //ms
        private bool IsActive(GameTime gameTime)
        {
            return (TimeOfLastIntersection + MinDurationBetweenIntersection < gameTime.TotalGameTime.TotalMilliseconds);
        }
    }
}
